<template>
  <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" append-to-body :visible.sync="visible" width="800px"
    top="8vh">
    <el-container>
      <el-main style="max-height:70vh">
        <el-form :model="dataForm"   ref="dataForm" @keyup.enter.native="dataFormSubmit()"
          label-width="150px">
          <el-form-item label="人员编号" prop="ryCode">
            <el-input v-model="dataForm.ryCode" placeholder="人员编号"></el-input>
          </el-form-item>
          <el-form-item label="姓名" prop="ryXm">
            <el-input v-model="dataForm.ryXm" placeholder="姓名"></el-input>
          </el-form-item>
          <el-form-item label="开始日期" prop="llKssj">
            <el-date-picker v-model="dataForm.llKssj" placeholder="建立时间"
                        type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item label="结束日期" prop="llJssj">
            <!-- <el-input v-model="dataForm.llJssj" placeholder="结束日期"></el-input>
             -->
              <el-date-picker v-model="dataForm.llJssj" placeholder="建立时间"
                        type="datetime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
          </el-form-item>
          <el-form-item label="工作单位" prop="ryGzdw">
            <el-input v-model="dataForm.ryGzdw" placeholder="工作单位"></el-input>
          </el-form-item>
          <!-- <el-form-item label="工作单位编码" prop="ryGzdwCode">
            <el-input v-model="dataForm.ryGzdwCode" placeholder="工作单位编码"></el-input>
          </el-form-item> -->
          <el-form-item label="职务或工种" prop="ryZwgz">
            <el-input v-model="dataForm.ryZwgz" placeholder="职务或工种"></el-input>
          </el-form-item>
          <el-form-item label="行政级别" prop="ryXzjb">
            <el-input v-model="dataForm.ryXzjb" placeholder="行政级别"></el-input>
          </el-form-item>
          <el-form-item label="技术职称" prop="ryJszc">
            <el-input v-model="dataForm.ryJszc" placeholder="技术职称"></el-input>
          </el-form-item>
          <el-form-item label="技能级别" prop="ryJnjb">
            <el-input v-model="dataForm.ryJnjb" placeholder="技能级别"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="llBz">
            <el-input v-model="dataForm.llBz" placeholder="备注"></el-input>
          </el-form-item>

        </el-form>
      </el-main>
    </el-container>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import {
    getObj,
    addObj,
    putObj
  } from '@/api/jiangjin/jiangjinryllb'


  export default {
    data() {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
            id: 0,
          ryCode: '',
          ryXm: '',
          llKssj: '',
          llJssj: '',
          ryGzdw: '',
          ryGzdwCode: '',
          ryZwgz: '',
          ryXzjb: '',
          ryJszc: '',
          ryJnjb: '',
          llBz: '',

        },
        dataRule: {
                 ryCode: [
            { required: true, message: '人员编号不能为空', trigger: 'blur' }
          ],
          ryXm: [
            { required: true, message: '姓名不能为空', trigger: 'blur' }
          ],
          llKssj: [
            { required: true, message: '开始日期不能为空', trigger: 'blur' }
          ],
          llJssj: [
            { required: true, message: '结束日期不能为空', trigger: 'blur' }
          ],
          ryGzdw: [
            { required: true, message: '工作单位不能为空', trigger: 'blur' }
          ],
          ryGzdwCode: [
            { required: true, message: '工作单位编码不能为空', trigger: 'blur' }
          ],
          ryZwgz: [
            { required: true, message: '职务或工种不能为空', trigger: 'blur' }
          ],
          ryXzjb: [
            { required: true, message: '行政级别不能为空', trigger: 'blur' }
          ],
          ryJszc: [
            { required: true, message: '技术职称不能为空', trigger: 'blur' }
          ],
          ryJnjb: [
            { required: true, message: '技能级别不能为空', trigger: 'blur' }
          ],
          llBz: [
            { required: true, message: '备注不能为空', trigger: 'blur' }
          ]
        }
      }
    },
 
    methods: {
      init(r,index) {
    
         this.dataForm.ryCode= r.ryCode,
         this.dataForm.ryXm= r.ryXm,
         this.dataForm.llKssj= r.llKssj,
         this.dataForm.llJssj= r.llJssj,
         this.dataForm.ryGzdw= r.ryGzdw,
         this.dataForm.ryGzdwCode= r.ryGzdwCode,
         this.dataForm.ryZwgz= r.ryZwgz,
         this.dataForm.ryXzjb= r.ryXzjb,
        this.dataForm.ryJszc= r.ryJszc,
        this.dataForm.ryJnjb= r.ryJnjb,
         this.dataForm.llBz= r.llBz,
        this.visible = true;
        this.canSubmit = true;

      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
              putObj(this.dataForm).then(data => {
                this.$notify.success('修改成功')
                this.visible = false
                this.$emit('refreshDataList',index)
              }).catch(() => {
                this.canSubmit = true;
              });
            } else {
             //console.log(this.dataForm)
              addObj(this.dataForm).then(data => {
                this.$notify.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList')
              }).catch(() => {
                this.canSubmit = true;
              });
            }
          }
        })
      }
    }
  }

</script>
